<template>
	<view class="classlist">
		<view>
			<uv-skeletons :loading="!classList.length && !noData" :skeleton="skeleton"></uv-skeletons>
		</view>
		<view class="content">
			<navigator :url="'/pages/preview/preview?id=' + item._id" class="item" v-for="item in classList" :key="item._id">
				<image :src="item.smallPicurl" mode="aspectFill"></image>
			</navigator>
		</view>
		<view class="loadingLayout" v-if="classList.length || noData">
			<uni-load-more :status="noData?'noMore':'loading'"></uni-load-more>
		</view>
	</view>
</template>

<script setup>
import { ref } from 'vue';
import { onLoad,onReachBottom,onShareAppMessage,onShareTimeline} from '@dcloudio/uni-app'
import { apiGetClass,apiHistoryList } from '@/api/apis.js'
import { goToHome } from '../../utils/common'
// 骨架屏样式
const skeleton = [{
	type: 'line',
	num: 50,
	gap: '50rpx',
	style: ['width: 200rpx;marginBottom: 50rpx;', 'height: 100rpx;', 'width: 500rpx;'],
}]
const classList = ref([])
const getClassList = async ()=>{
	let res = null
	if(queryParams.classid) res = await apiGetClass(queryParams)
	if(queryParams.type) res = await apiHistoryList(queryParams)
	classList.value = [...classList.value, ...res.data]
	uni.setStorage({
		key:'storageClassList',
		data:classList.value
	})
	if(res.data.length < queryParams.pageSize) noData.value = true
}
// 传递的id对象
const queryParams = {
	pageNum:1,
	pageSize:12
}

let pageName
onLoad((e)=>{
	let {id=null,name=null,type=null} = e;
	
	if(type) queryParams.type = type
	if(id) queryParams.classid = id
	
	pageName = name
	queryParams.classid = id
	// 修改分类列表顶部导航条
	uni.setNavigationBarTitle({
		title:name
	})
	// onLoad优先级比getClassList()低一点，所以把这个函数放里面
	getClassList()
})

// 触底加载
// 没有数据了
const noData = ref(false)
onReachBottom(()=>{
	if(noData.value) return
	queryParams.pageNum++
	getClassList()
})

//分享给好友
onShareAppMessage(()=>{
	return {
		title:"雨渐婷壁纸-"+pageName,
		path:"/pages/classlist/classlist?id=" + queryParams.classid + "&name=" + pageName
	}
})
//分享朋友圈
onShareTimeline(()=>{
	return {
		title:"雨渐婷壁纸",
		query:"id=" + queryParams.classid + "&name=" + pageName
	}
})
</script>

<style lang="scss" scoped>
.classlist{
	.content{
		display: grid;
		grid-template-columns: repeat(3,1fr);
		gap:5rpx;
		padding:5rpx;
		.item{
			height: 440rpx;
			image{
				width: 100%;
				height: 100%;
				display: block;
			}
		}
	}
}
</style>
